using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using DIS_DAL_WS.Models;

namespace DIS_DAL_WS.DTO
{
    [DataContract]
	public class WeeklyReportDTO
	{
        [DataMember]
		public int ID { get; set; }
        [DataMember]
		public int IDRestaurant { get; set; }
        [DataMember]
		public DateTime StartDate { get; set; }
        [DataMember]
		public DateTime EndDate { get; set; }
        [DataMember]
        public RestaurantDTO Restaurant { get; set; }

        public static WeeklyReportDTO Translate(WeeklyReport Entity)
        {
            if (Entity != null)
            {
                var dto = new WeeklyReportDTO
                {
                    ID = Entity.ID,
                    StartDate = Entity.StartDate.Value,
                    EndDate = Entity.EndDate.Value,
                    Restaurant = RestaurantDTO.TranslateBase(Entity.Restaurant)
                };
                if (Entity.IDRestaurant != null)
                {
                    dto.IDRestaurant = Entity.IDRestaurant.Value;
                }
                else
                {
                    dto.IDRestaurant = -1;
                }
                return dto;
            }
            return null;
        }

        public static WeeklyReport Reverse(WeeklyReportDTO obj)
        {
            var entity = new WeeklyReport
            {
                ID = obj.ID,
                StartDate = obj.StartDate,
                EndDate = obj.EndDate
            };
            if (obj.IDRestaurant != -1)
            {
                entity.IDRestaurant = obj.IDRestaurant;
            }
            return entity;
        }

        public void UpdateEntity(ref WeeklyReport entity)
        {
            entity.StartDate = StartDate;
            entity.EndDate = EndDate;
            if (IDRestaurant != -1)
            {
                entity.IDRestaurant = IDRestaurant;
            }
        }
	}
}